package yja.gzw.app.fragmentview

import android.util.Log
import android.widget.Toast
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import yja.gzw.app.R
import yja.gzw.app.adapter.FensiAdapter
import yja.gzw.app.base.BaseFragment
import yja.gzw.app.databinding.FragmentFensiBinding
import yja.gzw.app.model.UserData
import yja.gzw.app.model.bean.FocusDatafs
import yja.gzw.app.viewmodel.Mainviewmodel

class FensiFragment :BaseFragment<Mainviewmodel, FragmentFensiBinding>(R.layout.fragment_fensi), FensiAdapter.OnItemClickListener{



    private lateinit var fabiada: FensiAdapter
    override fun initView() {
        viewmodel.onfengsiwang(UserData.token, mapOf("page" to "1"))
    }

    override fun onResume() {
        super.onResume()
        viewmodel.onfengsiwang(UserData.token, mapOf("page" to "1"))

    }
    override fun dataObservese() {

        viewmodel.onguanzhuhequguan.observe(this, Observer {
            if(it.code==1){
                Log.e("关注状态","走到了1")
                viewmodel.onfengsiwang(UserData.token, mapOf("page" to "1"))

            }else{
                Toast.makeText(context,it.msg, Toast.LENGTH_SHORT).show()

            }

        })

        viewmodel.onfengsi.observe(this, Observer {
            if(it.code==1){

                binding.review.layoutManager=
                    LinearLayoutManager(context)
                fabiada= FensiAdapter(requireContext(),it.data.data,this)

                binding.review.adapter= fabiada

            }else{
                Toast.makeText(context,it.msg, Toast.LENGTH_SHORT).show()
            }

        })


    }

    override fun onItemClick(position: Int, uri: FocusDatafs) {
        viewmodel.onguanzhuhequguanwang(UserData.token, mapOf("user_id" to uri.user_id.toString()))



    }
}